package com.yiwei.zxp.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.ShareDetailActivity;
import com.yiwei.zxp.api.model.ShareGoldListModel;
import com.yiwei.zxp.util.DateTime;
import com.yiwei.zxp.util.Spans;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyShareMoneyTimeoutAdapter extends ItemAdapter<ShareGoldListModel.DatasBean, MyShareMoneyTimeoutAdapter.DefaultHolder> {

    private final int textSize28;
    private final int textSize24;

    private Context context;

    public MyShareMoneyTimeoutAdapter(Context context) {
        super(context);
        this.context = context;
        textSize28 = context.getResources().getDimensionPixelSize(R.dimen.x28);
        textSize24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_share_money_timeout, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ShareGoldListModel.DatasBean item = getItem(position);
        Spanned txtTwo = Spans.with(context).font("已领淘淘币 ", textSize28, 0xff999999).
                font(item.shared_gold + "元", textSize24, 0xff333333).
                build();
        holder.txtContentLeft.setText(txtTwo);
        Spanned txtThree = Spans.with(context).font("已领取时间 ", textSize28, 0xff999999).
                font(DateTime.toDate(item.true_back_time*1000), textSize24, 0xff333333).
                build();
        holder.txtContentRight.setText(txtThree);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShareDetailActivity.class);
                intent.putExtra("order_id", item.order_id);
                context.startActivity(intent);
                ((Activity) context).overridePendingTransition(R.anim.right_enter, R.anim.left_out);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_content_left)
        TextView txtContentLeft;
        @BindView(R.id.txt_content_right)
        TextView txtContentRight;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
